home *** CD-ROM | disk | FTP | other *** search
- ; SDQ.ASM 1/8/87, copyright Russ Eberhart
- ; Link with pcpads2c.bas, compiled to pcpads2c.obj, and prefix.obj
- ;
- data segment word public 'data'
- fa_stor dw 4 dup(?) ;store 4 channel factors here
- of_stor dw 4 dup(?) ;store 4 channel offsets here
- s_trace dw ? ;1=single trace 0=continuous
- s_table dw 4 dup(0) ;store 4 calculated channel counts
- nam_fil db 'c:data.dat',0h ;name of ramdisk file for data
- handle dw ? ;store file handle here
- s_data dw 2424d dup(0) ;store screenful of data here
- data ends
- ;
- dgroup group data ;define data group,loaded last
- ;
- stack segment word stack 'stack'
- stk dw 128 dup(?) ;define stack area
- stack ends
- ;
- code segment byte public 'code'
- assume cs:code,ds:dgroup
- ;
- public scndraw
- scndraw proc far
- ;
- push bp
- mov bp,sp ;BP points at BASIC stack
- ;now can read parameters
- ;from BASIC stack
- ;
- ;-----------------------
- ; Load factors, offsets and single-trace variable
- ;
- lea bx,fa_stor ;point to factor table
- mov di,22d ;set di to point at fac1%
- loop1: mov si,[bp+di] ;move fac/off/stn address to SI
- mov ax,[si] ;move value of variable into AX
- mov [bx],ax ;move value into table
- add bx,2 ;point to next word in table
- sub di,2 ;point to next variable on stack
- cmp di,4 ;done last variable?
- jnz loop1 ;if not done, jump to loop1
- ;-----------------------
- ; Check s_trace for "save data", if save, create c:data.dat file
- ; and write offsets and factors to it
- mov cx,s_trace ;move s_trace to CX to check for save
- and cx,2 ;check for binary 2 = save
- jz newsc ;if no 2, no save, jump to newscreen
- mov dx,offset nam_fil ;address of file name
- mov cx,0 ;normal file attribute
- mov ah,3ch ;create file function
- int 21h ;call dos
- mov handle,ax ;store handle
- jnc wr_parms ;if no error, write offsets and factors
- jmp getout ; if error, get out
- wr_parms:
- mov bx,handle ;put handle in BX
- mov dx,offset fa_stor ;address of bytes to write
- mov cl,16d ;put number of bytes to write in CL
- mov ch,0 ; and zero out CH
- mov ah,40h ;write to file function
- int 21h ;call dos
- jnc newsc ;if no error, go on
- jmp getout ; if error, get out
- ;-----------------------
- ; Set video mode, write screen labels and dot matrix
- ;
- newsc: mov ah,0 ;function 0, "set mode"
- mov al,6 ;mode 6: 640x200
- int 10h ;video I/O int sets mode
- ;
- mov cx,4 ;set up for four loops
- mov dh,00 ;initial row
- mov bh,0 ;page no. must be in BH
- ;
- wrt: mov ah,2 ;"set cursor" function
- inc dh ;DH=row=1
- mov dl,03 ;DL=column (0-79)
- int 10h ;video I/O sets cursor
- mov bl,07 ;color=7 (BH still 0)
- mov al,'4' ;char to print = 4
- mov ah,0eh ;"write tty" video service
- int 10h ;vid I/O prints "4"
- ;
- mov ah,2 ;set cursor
- inc dh ;DH=row=2
- mov dl,03 ;col=3
- int 10h ;set cursor to 2,3
- mov bl,07 ;color
- mov ax,0e33h ;"tty" service:char 3 to print
- int 10h ;prints 3
- ;
- mov ah,2 ;set cursor
- inc dh ;row=3
- mov dl,03 ;col=3
- int 10h ;set cur 3,3
- mov bl,07 ;color
- mov ax,0e32h ;"tty":2 to print
- int 10h ;prints 2
- ;
- mov ah,2 ;set cursor
- inc dh ;row=4
- mov dl,0 ;col=0
- int 10h ;set cur at 4,0
- mov bl,07 ;color
- mov ax,0e43h ;tty:C to print
- int 10h ;prints C, moves cursor
- mov bl,07 ;color
- mov ax,0e20h ;tty:(space) to print
- int 10h ;prints (space)
- mov bl,07 ;color
- mov ax,0e20h ;tty:(space) to print
- int 10h ;prints (sp)
- mov bl,07 ;color
- mov ax,0e31h ;tty:1 to print
- int 10h ;prints 1
- ;
- mov ah,2 ;set cursor
- inc dh ;row=5
- mov dl,0 ;col=0
- int 10h ;set cur at 5,0
- mov bl,07 ;color
- mov ax,0e48h ;tty:H to print
- int 10h ;prints H, moves cur
- mov bl,07 ;color
- mov ax,0e20h ;tty:(sp) to print
- int 10h ;print (sp)
- mov bl,07 ;color
- mov ax,0e20h ;tty:(sp) to print
- int 10h ;prints (sp)
- mov bl,07 ;color
- mov ax,0e30h ;tty:0 to print
- int 10h ;print 0
- ;
- mov ah,2 ;set cursor
- inc dh ;row=6
- mov dl,02 ;col=2
- int 10h ;set cursor 6,2
- mov bl,07 ;color
- mov ax,0e2dh ;tty:"-" to print
- int 10h ;prints "-"
- mov bl,07 ;color
- mov ax,0e31h ;tty:1 to print
- int 10h ;print 1
- ;
- dec cx ;another loop done
- jcxz go_on ;go on if 4 loops done
- jmp wrt ;do another loop if not
- ;
- go_on: mov cl,34h ;put chan no (4) into CL
- mov dl,0 ;column 0 for all
- mov dh,0 ;initialize row
- ;
- wch: mov ah,2 ;set cursor
- add dh,6 ;set row to 6,12,18 or 24
- int 10h ;set cursor to 0,6or12etc
- mov bl,07 ;color
- mov ah,0eh ;tty
- mov al,cl ;move chan no into al
- int 10h ;prints channel no
- dec cl ;reduce channel no
- cmp cl,30h ;done?
- jnz wch ;no, loop to wch
- ;
- ;now write dot matrix
- mov cx,39d ;column number
- hdots: mov dx,11d ;row number
- vdots: mov ax,0c01h ;write dot:color 1 ????? 7?
- int 10h ;write dot
- add dx,8d ;add 8d to row no
- cmp dx,196d ;compare with 196 (max 195d)
- jb vdots ;more vertical if less
- add cx,30d ;add 30 to column
- cmp cx,640d ;at right of screen yet?
- jb hdots ;no, another vertical line of dots
- ;-----------------------
- ; Read channels at port, calculate time counts for each
- ;
- mov si,39d ;set initial column count for data pts
- nw_col: mov dx,0201h ;Game Port address
- mov cx,00ffh ;counter for loop; gives same res as BAS
- mov bx,000fh ;bh:# pushes bl:4-channel mask
- cli ;briefly disable interrupts
- out dx,al ;fire the game-port one-shots
- stick1: in al,dx ;read the game port
- and al,0fh ;mask off switches, allow 4-chan
- cmp al,bl ;any one-shots dropped yet?
- loopz stick1 ;loop until one drops or timeout
- ; loop if zero flag set & cx not 0
- jcxz stick2 ;jump on timeout to stick2 (only exit)
- xor al,bl ;set to 1 those dropped (drop mask)
- mov ah,cl ;put countdown time count in AH
- push ax ;save countdown:drop-mask on stack
- inc bh ;increment # pushes (# dropmasks)
- xor bl,al ;new dropmask for remaining channels
- jmp stick1 ;jump until TIMEOUT
- ;could cmp bl,0 : jnz stick1 : here
- stick2: or bh,bh ;test for no valid data (no pushes)
- jz exit ; if timed out with no drops
- mov dl,bh ;number of stack pushes (dropmasks)
- stick3: lea bx,s_table ;point to result table
- pop ax ;get last-saved countdown:dropmask
- not ah ;convert to plus time interval
- add ah,1 ; via two's complement
- mov cx,0004h ;loop counter for number of channels
- stick4: shr al,1 ;shift LSB to carry
- jnb stick5 ;jump if CF=0 (if LSB was 0)
- mov [bx],ah ;if LSB was 1, save val in s_table
- stick5: add bx,2 ;point to next s_table location
- loop stick4 ;test next bit, do 4 times total
- dec dl ;dec. pops (countdown:dropmask)'s remaining
- jnz stick3 ;get next data from stack if any left
- exit: sti ;set interrupts, exit this area
- ;-----------------------
- ; Get results, calculate and plot data points
- ;
- mov bx,0 ;set up offsets into tables
- mov di,187d ;put bottom (Ch 1) zero line in DI
- read1: mov cx,s_table[bx] ;get reading into CX
- mov dx,0 ;put zeros in DX (high word)
- mov ax,0ffffh ;put 65535d in ax
- div cx ;65535/reading, result in AX
- mov cx,of_stor[bx] ;get offset in CX
- sub ax,cx ;subtract offset
- jnb read2 ;jump if ax>=cx, -> pos value
- ;-----------------------
- not ax ;if neg value, convert to plus
- add ax,1 ; via 2's complement
- mov cl,3 ;set up shift left 3
- shl ax,cl ; shift left 3, multiplies by 8
- mov dx,0 ;put zeros in DX (high word)
- ;DX:AX now has val for division by fac
- mov cx,fa_stor[bx] ;get factor in CX
- div cx ;8*(1/data - offset)/factor, res in AX
- mov dx,di ;put zero line position in DX
- add dx,ax ;get vertical (row) value to plot
- ; (value is less than zero)
- jmp plot ;go to plot point
- ;-----------------------
- read2: mov cl,3 ;set up shift left 3
- shl ax,cl ; shift left 3, multiplies by 8
- mov dx,0 ;put zeros in DX (high word)
- ;DX:AX now has val for div by factor
- mov cx,fa_stor[bx] ;get factor in CX
- div cx ;8*91/data - offset)/factor, res in AX
- mov dx,di ;put zero line position in DX
- sub dx,ax ;get vertical (row) value to plot
- ; (value is positive voltage)
- ;-----------------------
- plot: mov cx,si ;move column number into CX
- mov ax,0c01h ;write-dot:color-1
- int 10h ;write dot
- sub di,48d ;set new zero line for next channel
- add bx,2 ;set new offset into tables
- cmp bx,8 ;are all four channels plotted?
- jnz read1 ; no, so get next value to plot
- mov cx,s_trace ;yes, so see if "save" is active
- and cx,2 ; it is if 2 is set
- jz n_save ; if no save, go to n_save
- mov bx,0 ;set BX as index to zero
- mov di,si ;put column count in DI
- sub di,39d ;normalize to make first column = 0
- shl di,1 ;multiply di by 2, then again
- shl di,1 ; by 2, so mult by 4 so far,
- shl di,1 ; then again by 2, net mult by 8
- xy: mov ax,[s_table + bx] ;put result word in AX
- mov [s_data+di+bx],ax ;put word into data table
- add bx,2 ;increment bx 2 bytes
- cmp bx,8 ;have we put all 4 values in table?
- jnz xy ; no, put in another word
- n_save: inc si ;increment column index
- cmp si,639 ;are all columns plotted?
- jz trck ;yes, go to single-trace check
- jmp nw_col ;no, fire one-shots again
- ; If save is activated, save s_data to c:data.dat
- trck: mov cx,s_trace
- and cx,2 ;see if save is active
- jz ns_trck ;if no save, jump to ns_trck
- mov bx,handle ;put handle in BX
- mov dx,offset s_data ;put address of data table in DX
- mov cx,4800d ;put number of bytes in CX
- mov ah,40h ;write to file function
- int 21h ;call dos
- jnc ns_trck ;if no error, go on
- jmp getout ; if error, get out
- ns_trck: mov cx,s_trace ;move single-trace to CX 1-yes 0-no
- and cx,1 ; are we in single trace mode?
- jnz newtr ; yes, jump to wait for key
- mov ah,0bh ;get keyboard status no wait
- int 21h ;see if key is pressed
- inc al ; if AL ffh then
- jz newtr ; key pressed, see which one
- jmp newsc ;no key, make new screen
- newtr: mov ah,8h ;load keyboard wait function
- int 21h ;get keyboard input
- cmp al,27d ; is it escape?
- jz f_close ;yes, exit the program
- jmp newsc ;no, make new screen
- ;
- ; Close the file if it was opened
- f_close:
- mov cx,s_trace ;see if save is active
- and cx,2 ; it is if 2 is set
- jz getout ; if not, exit program
- mov bx,handle ; if it is, put handle in BX
- mov ah,3eh ;close handle function
- int 21h ;call dos
- ;
- getout: mov ah,0 ;video funtion 0, set mode
- mov al,3 ;mode 3, 80x25 color, text mode
- int 10h ;call video i/o routine
- pop bp ;prepare to return to BASIC
- ret 18d ;return to BASIC, pop 9 words
- scndraw endp
- code ends ;end of code segment
- end